package com.soujiayi.adapter;

import java.util.ArrayList;
import java.util.List;

import com.soujiayi.activity.R;
import com.soujiayi.activity.R.drawable;
import com.soujiayi.activity.R.id;
import com.soujiayi.activity.R.layout;
import com.soujiayi.activity.R.string;
import com.soujiayi.util.Constants;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductSortListAdapter extends BaseAdapter{
	
	private List<Integer> data;
	private LayoutInflater mInflater;
	private String DEFAUT;
	private String PRICE_ASC;
	private String PRICE_DESC;
	//private String SALES_VOLUME_DESC;
	public int selectedItem = 0;
	
	public ProductSortListAdapter(Context context) {
		this.data = new ArrayList<Integer>();
		this.data.add(Constants.PRODUCT_SORT_DEFAULT);
		this.data.add(Constants.PRODUCT_SORT_PRICE_ASC);
		this.data.add(Constants.PRODUCT_SORT_PRICE_DESC);
		//this.data.add(Constants.PRODUCT_SORT_SALES_VOLUME_DESC);
		
		this.DEFAUT = context.getResources().getString(R.string.product_sort_default);
		this.PRICE_ASC = context.getResources().getString(R.string.product_sort_price_asc);
		this.PRICE_DESC = context.getResources().getString(R.string.product_sort_price_desc);
		//this.SALES_VOLUME_DESC = context.getResources().getString(R.string.product_sort_sales_volum_desc);
		
		this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		ViewHolder holder;
		if(view == null){
			view = mInflater.inflate(R.layout.product_sort_list_item, null);
			holder = new ViewHolder(); 
			holder.sortItem = (TextView)view.findViewById(R.id.product_sort_sortItem);
			holder.sortChecked = (TextView)view.findViewById(R.id.product_sort_sortChecked);
			view.setTag(holder);
		}else{
			holder = (ViewHolder)view.getTag();
		}
		
		bindView(holder,data.get(position));
		
		return view;
	}
	
	private void bindView(ViewHolder holder,Integer item){
		switch(item){
			case Constants.PRODUCT_SORT_DEFAULT: 
				holder.sortItem.setText(this.DEFAUT);
				break;
			case Constants.PRODUCT_SORT_PRICE_ASC: 
				holder.sortItem.setText(this.PRICE_ASC);
				break;
			case Constants.PRODUCT_SORT_PRICE_DESC: 
				holder.sortItem.setText(this.PRICE_DESC);
				break;
//			case Constants.PRODUCT_SORT_SALES_VOLUME_DESC: 
//				holder.sortItem.setText(this.SALES_VOLUME_DESC);
//				break;
			default:
				break;
		}
		if(this.selectedItem == item){
			holder.sortChecked.setVisibility(View.VISIBLE);
		}else{
			holder.sortChecked.setVisibility(View.INVISIBLE);
		}

	}
	
	private static class ViewHolder {
		TextView sortItem;
		TextView sortChecked;
	}

}
